--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.
--Data Schema For Version 0.0.0.0
--Generated on 2010-07-14 16:13:12

--CREATE TABLE [CUSTOMER]
if not exists(select * from sysobjects where name = 'CUSTOMER' and xtype = 'U')
CREATE TABLE [dbo].[CUSTOMER] (
[address] [VarChar] (50) NULL ,
[city] [VarChar] (50) NULL ,
[country] [VarChar] (50) NULL ,
[fax] [VarChar] (50) NULL ,
[first_name] [VarChar] (50) NOT NULL ,
[last_name] [VarChar] (50) NOT NULL ,
[middle_name] [VarChar] (50) NULL ,
[phone] [VarChar] (50) NULL ,
[postal_code] [VarChar] (50) NULL ,
[region] [VarChar] (50) NULL ,
[user_id] [Int] IDENTITY (1, 1) NOT NULL ,
[modified_by] [Varchar] (50) NULL ,
[modified_date] [DateTime] CONSTRAINT [DF__CUSTOMER_MODIFIED_DATE] DEFAULT GetDate() NULL ,
[created_by] [Varchar] (50) NULL ,
[created_date] [DateTime] CONSTRAINT [DF__CUSTOMER_CREATED_DATE] DEFAULT GetDate() NULL ,
[time_stamp] [timestamp] NOT NULL 
) ON [PRIMARY]


GO

--APPEND AUDIT TRAIL CREATE for Table [CUSTOMER]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_by' and o.name = 'CUSTOMER')
ALTER TABLE [dbo].[CUSTOMER] ADD [created_by] [Varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_date' and o.name = 'CUSTOMER')
ALTER TABLE [dbo].[CUSTOMER] ADD [created_date] [DateTime] CONSTRAINT [DF__CUSTOMER_CREATED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL MODIFY for Table [CUSTOMER]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_by' and o.name = 'CUSTOMER')
ALTER TABLE [dbo].[CUSTOMER] ADD [modified_by] [Varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_date' and o.name = 'CUSTOMER')
ALTER TABLE [dbo].[CUSTOMER] ADD [modified_date] [DateTime] CONSTRAINT [DF__CUSTOMER_MODIFIED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL TIMESTAMP for Table [CUSTOMER]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'time_stamp' and o.name = 'CUSTOMER')
ALTER TABLE [dbo].[CUSTOMER] ADD [time_stamp] [timestamp] NOT NULL

--PRIMARY KEY FOR TABLE [CUSTOMER]
if not exists(select * from sysobjects where name = 'PK_CUSTOMER' and xtype = 'PK')
ALTER TABLE [dbo].[CUSTOMER] WITH NOCHECK ADD 
CONSTRAINT [PK_CUSTOMER] PRIMARY KEY CLUSTERED 
(
	[user_id]
) ON [PRIMARY] 
GO

--DROP ANY AUDIT TRIGGERS FOR [CUSTOMER]
if exists(select * from sysobjects where name = '__TR_CUSTOMER__INSERT' AND xtype = 'TR')
DROP TRIGGER [__TR_CUSTOMER__INSERT]
GO
if exists(select * from sysobjects where name = '__TR_CUSTOMER__UPDATE' AND xtype = 'TR')
DROP TRIGGER [__TR_CUSTOMER__UPDATE]
GO
if exists(select * from sysobjects where name = '__TR_CUSTOMER__DELETE' AND xtype = 'TR')
DROP TRIGGER [__TR_CUSTOMER__DELETE]
GO

